﻿@inherits AdminPage

<CascadingValue Value="this">
    <Layout Style="min-height:100vh;">
        @if (IsLoaded)
        {
            <Sider Breakpoint="@BreakpointType.Lg" CollapsedWidth="60" Collapsible>
                <div class="kui-logo"><img src="@Index.LogoUrl" /></div>
                <AntMenu Accordion="Context.UserSetting.Accordion" Items="UserMenus" OnClick="e=>Context.Navigate(e)" />
            </Sider>
            <Layout>
                <Header Class="kui-header">
                    <NavBreadcrumb CurrentMenu="CurrentMenu" OnHome="OnHome" />
                    <NavTopRight OnMenuClick="OnMenuClick" />
                </Header>
                <Content Class="@Content">
                    @if (Context.UserSetting.MultiTab)
                    {
                        <PageTabs @ref="tabs" Menu="CurrentMenu" Items="TabMenus" />
                    }
                    else
                    {
                        <PageSingle @ref="page" Menu="CurrentMenu" />
                    }
                </Content>
                @if (AntConfig.Option.Footer != null)
                {
                    <Footer Style="text-align:center">@AntConfig.Option.Footer</Footer>
                }
                else
                {
                    <Footer Style="text-align:center"><PageFooter /></Footer>
                }
            </Layout>
        }
    </Layout>
</CascadingValue>

<Drawer Closable="true" @bind-Visible="showSetting" Placement="right" Title='(Language["Nav.Setting"])' Width="300">
    <Known.Blazor.SettingForm @ref="setting" />
</Drawer>

@code{
    private PageTabs tabs;
    private PageSingle page;
    private bool showSetting = false;
    private Known.Blazor.SettingForm setting;
    private string Content => Context.UserSetting.MultiTab ? "kui-tabs" : "kui-page";

    [CascadingParameter] private IndexPage Index { get; set; }

    protected override void RefreshPage()
    {
        base.RefreshPage();
        tabs?.StateChanged();
        page?.StateChanged();
        setting?.StateChanged();
    }

    private void OnHome() => OnMenuClick("home");

    private void OnMenuClick(string id)
    {
        switch (id)
        {
            case "home":
                Context.NavigateToHome();
                break;
            case "profile":
                Context.NavigateToUserProfile();
                break;
            case "logout":
                UI.Confirm(Language["Tip.Exits"], SignOutAsync);
                break;
            case "setting":
                showSetting = true;
                StateChanged();
                break;
        }
    }
}